//
//  RanDynamicTableViewCell.m
//  ThusMyStyle
//
//  Created by Ran on 15/11/12.
//  Copyright (c) 2015年 gintong. All rights reserved.
//

#import "RanDynamicTableViewCell.h"

@implementation RanDynamicTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
        self.headView.image = [UIImage imageNamed:@"1.jpg"];
        self.nameLabel = [[TYAttributedLabel alloc] initWithFrame:CGRectMake(60, 15, 100, 20)];
        self.locationLabel = [[TYAttributedLabel alloc] initWithFrame:CGRectMake(100, 30, 100, 20)];
        self.contentLabel = [[TYAttributedLabel alloc] initWithFrame:CGRectMake(10, 60, 300, 100)];
        self.imageHolder = [[UIView alloc] initWithFrame:CGRectMake(10, 170, 300, 100)];
        self.commentList = [[UITableView alloc] init];
        
        [self.contentView addSubview:self.headView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.locationLabel];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.imageHolder];
        [self.contentView addSubview:self.commentList];
        
        self.commentList.dataSource = self;
        self.commentList.delegate = self;
        [self.commentList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return self;
}

- (void)setComms:(NSArray *)comms
{
    _comms = comms;
    [self.commentList reloadData];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.comms.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = @"fdsakfdaslfjdskal";
    return cell;
}

#pragma mark - UITabelViewDelegagte

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TYTextContainer *container = self.comms[indexPath.row];
    return container.textHeight;
}

@end
